#define _CRT_SECURE_NO_WARNINGS 1

#include "Stack.h"

void w::StackInit(Stack* ps, int n)
{
	
	ps->capacity = n;
	ps->arr = (int*)malloc(sizeof(int) * n);
	if (ps->arr == NULL)
	{
		perror("malloc fail");
		return;
	}
	ps->top = 0;

}

void w::StackPush(Stack* ps, int x)
{
	if (ps->top == ps->capacity)
	{
		int* ptr = (int*)realloc(ps->arr, sizeof(int)*(ps->capacity) * 2);
		if (ptr == nullptr)
		{
			
			perror("realloc fail");
			return;
		}
		ps->arr = ptr;
		ps->capacity *= 2;
	}
	ps->arr[ps->top] = x;
	ps->top++;
}

void w::StackPrint(Stack* ps)
{
	for (int i = 0; i < ps->top; i++)
	{
		cout << ps->arr[i] << endl;
	}
}